package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.OhFeiGoodsBrandDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.OhFeiGoodsBrandInfo;

@Repository("ohFeiGoodsBrandDAO")
public class OhFeiGoodsBrandDAOImpl extends SuperDAO<OhFeiGoodsBrandInfo>
		implements OhFeiGoodsBrandDAO {

	/**
	 * 产品品牌分页查询
	 * 
	 * @param info
	 * @return
	 */
	@Override
	public Pagination<OhFeiGoodsBrandInfo> queryPaginationList(
			OhFeiGoodsBrandInfo info) {
		Pagination<OhFeiGoodsBrandInfo> paginationList = null;
		Integer rowCount = queryRowCount(info);

		info.calculate();
		List<OhFeiGoodsBrandInfo> list = queryResultList(info);

		paginationList = this.queryPagination(rowCount, list, info);

		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(OhFeiGoodsBrandInfo info) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.OhFeiGoodsBrandMapper.queryRowCount", info);

		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param info
	 * @return
	 */
	private List<OhFeiGoodsBrandInfo> queryResultList(OhFeiGoodsBrandInfo info) {
		List<OhFeiGoodsBrandInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.OhFeiGoodsBrandMapper.queryResultList", info);

		return list;
	}

	/**
	 * 记录新增
	 * 
	 * @param info
	 */
	@Override
	public void insert(OhFeiGoodsBrandInfo info) {
		this.getSqlSession().insert("mybatis.xml.OhFeiGoodsBrandMapper.insert",
				info);
	}

	/**
	 * 根据小类商品Id，查询单条记录
	 * 
	 * @param cardId
	 * @return
	 */
	@Override
	public OhFeiGoodsBrandInfo queryByCardId(String cardId) {
		OhFeiGoodsBrandInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.OhFeiGoodsBrandMapper.queryByCardId", cardId);

		return info;
	}

	/**
	 * 记录更新
	 * 
	 * @param info
	 */
	@Override
	public void update(OhFeiGoodsBrandInfo info) {
		this.getSqlSession().update("mybatis.xml.OhFeiGoodsBrandMapper.update",
				info);

	}

	@Override
	public List<String> queryAllCardId() {
		List<String> cardIdList = this.getSqlSession().selectList(
				"mybatis.xml.OhFeiGoodsBrandMapper.queryAllCardId");
		return cardIdList;
	}

}
